home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / REDIRECT.SWG / 0004_REDIRCT2.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  98 lines

  1. {
  2. > When pkzip executes... it Writes to the screen and scrolls my
  3. > screen up. Is there a way in which I can prevent pkzip from writing
  4. > to the screen.
  5.  
  6. This thread comes up a bunch.  Here's a tried and tested solution :
  7. }
  8. Unit Redir;
  9.  
  10. { Redirect input, output, and errors }
  11.  
  12. Interface
  13.  
  14. Procedure RedirectInput (TextFile : String);
  15. Procedure RedirectOutput (TextFile : String);
  16. Procedure StdInput;
  17. Procedure StdOutput;
  18.  
  19. Implementation
  20.  
  21. Uses
  22.   Dos;
  23.  
  24. Const
  25.     STDin  = 0;
  26.     STdoUT = 1;
  27.     STDERR = 2;
  28.  
  29. Procedure Force_Dup (Existing,              { Existing handle         }
  30.                      Second     : Word);    { Handle to place it to   }
  31.  
  32. Var
  33.   R : Registers;
  34.  
  35. begin
  36.  
  37.     r.AH := $46;
  38.     r.BX := Existing;
  39.     r.CX := Second;
  40.  
  41.     MSDos (R);
  42.  
  43.     if (r.Flags and FCarry) <> 0 then
  44.         Writeln ('Error ', r.AX, ' changing handle ', Second);
  45. end;
  46.  
  47.  
  48. Procedure RedirectInput (TextFile : String);
  49.  
  50. Var
  51.     TF : Text;
  52.  
  53. begin
  54.     Assign (TF, TextFile);
  55.     Reset (TF);
  56.     Force_Dup (TextRec (TF).Handle, STDin);
  57. end;
  58.  
  59. Procedure RedirectOutput (TextFile : String);
  60.  
  61. Var
  62.     TF : Text;
  63.  
  64. begin
  65.     Assign (TF, TextFile);
  66.     ReWrite (TF);
  67.     Force_Dup (TextRec (TF).Handle, STdoUT);
  68.     Force_Dup (TextRec (TF).Handle, STDERR);
  69. end;
  70.  
  71. Procedure StdInput;
  72.  
  73. begin
  74.     Assign (Input, '');
  75.     Reset (Input);
  76. end;
  77.  
  78. Procedure StdOutPut;
  79.  
  80. begin
  81.     Assign (Output, '');
  82.     ReWrite (Output);
  83. end;
  84.  
  85. end.
  86.  
  87. {------ cut here ------}
  88. {
  89. In your Program :
  90.  
  91. Uses Redir;
  92.  
  93. begin
  94.      RedirectOutput ('LOGFile.OUT');
  95.      Exec ('PKZIP.EXE', '');
  96.      StdOutPut;
  97. end.
  98. }